//
//  WZTabBar.swift
//  weibo
//
//  Created by mac on 16/2/24.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit

class WZTabBar: UITabBar {

    override init(frame: CGRect) {
        
        super.init(frame: frame)
        setUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
   private func setUI(){
        
        addSubview(composeButton)
    }
    
    lazy var composeButton = {()->UIButton in
          let buttton = UIButton()
        
        buttton.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        buttton.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        
        buttton.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        buttton.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
        
        
        return buttton
    }()
    
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        var index: Int = 0
        //
        let width = UIScreen.mainScreen().bounds.size.width / 5
        let height = bounds.size.height
        
        for subview in subviews{
            
            if subview.isKindOfClass(NSClassFromString("UITabBarButton")!){
                
                subview.frame = CGRectMake(CGFloat(index++) * width, 0, width, height)
                
            }
            if index == 2{index++}
            
        }
        
        composeButton.frame = CGRectMake(2 * width, 0, width, height)
        
        
    }
    
}


